#include #include using namespace std; void translatePhraseToPigLatin(string& phrase); void main() { string phrase; cout << "Enter the phrase:"; getline(cin,phrase); translatePhraseToPigLatin(phrase); cout << phrase << endl; } int split(string words[], string phrase, char delimiter) { int wordCount = 0; string word = ""; for(int i = 0; i < phrase.length(); i++) { if(phrase.at(i) == delimiter) { //reached the end of a word words[wordCount] = word; word = ""; wordCount++; } else { word.push_back(phrase.at(i)); } } if(word != "") { words[wordCount] = word; wordCount++; } return wordCount; } int leadingConsonantCount(string word) { int result = 0; while(word[result] != 'a' && word[result] != 'A' && word[result] != 'e' && word[result] != 'E' && word[result] != 'i' && word[result] != 'I' && word[result] != 'o' && word[result] != 'O' && word[result] != 'u' && word[result] != 'U' && result < word.length()) { result++; } return result; } void translateWordToPigLatin(string& word) { //this th int i = leadingConsonantCount(word); string leadingConsonants = word.substr(0, i); word = word.substr(i); //moved the "is" back to the begining of the word word.append(leadingConsonants); //isth if(i == 0) { word.append("yay"); } else { word.append("ay"); //isthay } } void translatePhraseToPigLatin(string& phrase) { //string words[] = phrase.split(" "); string words[1000]; int wordCount = split(words, phrase, ' '); //translate each word in words //place the tanslated words into the phrase phrase = ""; for(int i = 0; i < wordCount; i++) { translateWordToPigLatin(words[i]); phrase += words[i]; if(i < wordCount -1) { phrase += " "; } } }